<?php
require_once("database.php");
class xl_thanh_vien extends database
{
	function danh_sach($vi_tri, $so_luong)
	{
		$vi_tri = intval($vi_tri);
		$so_luong = intval($so_luong);
		$sql = "select * from thanh_vien limit $vi_tri, $so_luong";
		$this->setQuery($sql);
		return $this->loadAllRow();
	}
	function so_luong()
	{
		$sql = "select count(*) from thanh_vien";
		$this->setQuery($sql);
		return $this->loadResult();
	}
	function xem($ma)
	{
		$ma = intval($ma);

		$sql = "select * from thanh_vien where ma = '$ma'";
		$this->setQuery($sql);
		return $this->loadRow();
	}
	function xoa($ma)
	{
		$ma = intval($ma);

		$sql = "delete from thanh_vien where ma = '$ma'";
		$this->setQuery($sql);
		return $this->query();
	}
	function them($ho_ten, $username, $mat_khau, $dia_chi, $email, $dien_thoai, $ten_cong_ty, $ma_so_thue, $trang_thai)
	{
		$ho_ten = stripslashes($ho_ten);
		$ho_ten = addslashes($ho_ten);
		
		$username = stripslashes($username);
		$username = addslashes($username);
		
		$mat_khau = stripslashes($mat_khau);
		$mat_khau = addslashes($mat_khau);
		
		$dia_chi = stripslashes($dia_chi);
		$dia_chi = addslashes($dia_chi);
		
		$email = stripslashes($email);
		$email = addslashes($email);
		
		$dien_thoai = stripslashes($dien_thoai);
		$dien_thoai = addslashes($dien_thoai);
		
		$ten_cong_ty = stripslashes($ten_cong_ty);
		$ten_cong_ty = addslashes($ten_cong_ty);
		
		$ma_so_thue = intval($ma_so_thue);
		$trang_thai = intval($trang_thai);

		$sql = "INSERT INTO thanh_vien(ho_ten,username,mat_khau,dia_chi,email,dien_thoai,ten_cong_ty,ma_so_thue,trang_thai) VALUES ('$ho_ten','$username','$mat_khau','$dia_chi','$email','$dien_thoai','$ten_cong_ty','$ma_so_thue','$trang_thai')";
		$this->setQuery($sql);
		return $this->query();
	}
	function cap_nhat($ma, $ho_ten, $username, $mat_khau, $dia_chi, $email, $dien_thoai, $ten_cong_ty, $ma_so_thue, $trang_thai)
	{
		$ma = intval($ma);
		
		$ho_ten = stripslashes($ho_ten);
		$ho_ten = addslashes($ho_ten);
		
		$username = stripslashes($username);
		$username = addslashes($username);
		
		$mat_khau = stripslashes($mat_khau);
		$mat_khau = addslashes($mat_khau);
		
		$dia_chi = stripslashes($dia_chi);
		$dia_chi = addslashes($dia_chi);
		
		$email = stripslashes($email);
		$email = addslashes($email);
		
		$dien_thoai = stripslashes($dien_thoai);
		$dien_thoai = addslashes($dien_thoai);
		
		$ten_cong_ty = stripslashes($ten_cong_ty);
		$ten_cong_ty = addslashes($ten_cong_ty);
		
		$ma_so_thue = intval($ma_so_thue);
		$trang_thai = intval($trang_thai);

		$sql ="UPDATE thanh_vien SET ho_ten= '$ho_ten', username= '$username', mat_khau= '$mat_khau', dia_chi= '$dia_chi', email= '$email', dien_thoai= '$dien_thoai', ten_cong_ty= '$ten_cong_ty', ma_so_thue= '$ma_so_thue', trang_thai= '$trang_thai' WHERE ma = '$ma'";
		$this->setQuery($sql);
		return $this->query();
	}
	function tim_kiem ($tu_khoa)
	{
		$sql = "select * from thanh_vien where	$ho_ten like %tu_khoa% or 	$username like %tu_khoa% or 	$mat_khau like %tu_khoa% or 	$dia_chi like %tu_khoa% or 	$email like %tu_khoa% or 	$dien_thoai like %tu_khoa% or 	$ten_cong_ty like %tu_khoa%"; 
		$this->setQuery($sql);
		return $this->loadAllRow();	
	}
 }
?>